How PIR Sensor Works and How To Use It with nodemcu

Click Here to View Step by Step

What is a PIR sensor?

PIR sensors allow you to sense motion, generally used to detect whether a human has moved in or out of the sensors range. They are small, inexpensive, low-power, easy to use and don't wear out.

For that reason they are commonly found in appliances and gadgets used in homes or businesses. They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors.

Output :

Digital pulse high (3V) when triggered (motion detected) and digital low when idle (no motion detected). Pulse lengths are determined by resistors and capacitors on the PCB and differ from sensor to sensor. Sensitivity range: up to 20 feet (6 meters) 110 degrees x 70 degrees detection range.

 

 


 

Description 

The PIR sensor that we use in this project is of small size and range of 6 meters If the PIR sensor detects some movement in its range will send to relay to open the light
 Make the connections as per the diagram given below and then upload the code.
 

int Status = 12;  // Digital pin D6
int sensor = 13;  // Digital pin D7
void setup() {
  Serial.begin(9600);        // initialize serial
  pinMode(sensor, INPUT);   // declare sensor as input
  pinMode(Status, OUTPUT);  // declare LED as output
      digitalWrite (Status, LOW);
}
void loop() {
long state = digitalRead(sensor);
    if(state == HIGH) {
      digitalWrite (Status, HIGH);
      Serial.println("Motion detected!");
      delay(1000);
    }
    else {
      digitalWrite (Status, LOW);
      Serial.println("Motion absent!");
      delay(1000);
      }
}